package com.ynny.librarysystemmanager.controller;

import com.ynny.librarysystemmanager.common.R;
import com.ynny.librarysystemmanager.entity.User;
import com.ynny.librarysystemmanager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @GetMapping("/list")
    public R list(@RequestBody User user){

        List<User> users = userService.findAll(user);

        return R.ok(users);
    }


    @PostMapping("/add")
    public R add(@RequestBody User user){

        int result = userService.addUser(user);

        return R.ok(result);
    }


    @PutMapping("/update")
    public R update(@RequestBody User user){

        int result = userService.updateUser(user);

        return R.ok(result);
    }



    //禁用用户  1 禁用   0可用
    @PostMapping("/disable/{userId}/{status}")
    public R disable(@PathVariable("userId") Integer userId ,
                     @PathVariable("isDelete") Integer status){

        int result = userService.disableUser(userId , status);

        return R.ok(result);
    }
}